package net.maku.system.controller;

import java.util.List;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.framework.operatelog.annotations.OperateLog;
import net.maku.framework.operatelog.enums.OperateTypeEnum;
import net.maku.system.convert.SysContractTypeConvert;
import net.maku.system.entity.SysContractTypeEntity;
import net.maku.system.query. SysContractTypeQuery;
import net.maku.system.service. SysContractTypeService;
import net.maku.system.vo. SysContractTypeVO;

/**
 * 附件管理
 *
 * @author 阿沐 babamu@126.com
 * <a href="https://maku.net">MAKU</a>
 */
@RestController
@RequestMapping("sys/contract/type")
@Tag(name = "附件管理")
@AllArgsConstructor
public class SysContractTypeController {
    private final SysContractTypeService contractTypeService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('sys:contract:page')")
    public Result<PageResult< SysContractTypeVO>> page(@ParameterObject @Valid  SysContractTypeQuery query) {
        PageResult<SysContractTypeVO> page = contractTypeService.page(query);

        return Result.ok(page);
    }

    @PostMapping
    @Operation(summary = "保存")
    @OperateLog(type = OperateTypeEnum.INSERT)
    public Result<String> save(@RequestBody  SysContractTypeVO vo) {
    	contractTypeService.save(vo);

        return Result.ok();
    }
    
    @PutMapping
    @Operation(summary = "保存")
    @OperateLog(type = OperateTypeEnum.INSERT)
    public Result<String> update(@RequestBody  SysContractTypeVO vo) {
    	contractTypeService.update(vo);

        return Result.ok();
    }
    
    @GetMapping("{id}")
    @Operation(summary = "信息")
    public Result<SysContractTypeVO> get(@PathVariable("id") Long id) {
        SysContractTypeEntity entity = contractTypeService.getById(id);

        SysContractTypeVO vo = SysContractTypeConvert.INSTANCE.convert(entity);



        return Result.ok(vo);
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @OperateLog(type = OperateTypeEnum.DELETE)
    public Result<String> delete(@RequestBody List<Long> idList) {
    	contractTypeService.delete(idList);

        return Result.ok();
    }
}